#!/bin/bash
# script by: Matthew Jaffee

# script to compile topaz source files, put them in the jar, and re-sign it
# either set TOPAZHOME to to the root topaz dir (containing chrome.manifest, install.rdf etc)
# or run from within java_src/jTopaz/ if you want it to work right

# currently you need to pass the names of java files you modified as arguments, but w/o the .java
# issues could arise if one depends on another -- you can always revert to doing one at a time
# EX: ./topazcompile.sh GridFTPClientWrapper MyProxyThread

# please email jaffee@udel.edu with problems/bugs

cd ..
cd ..

if [ "$TOPAZHOME" = "" ] ; then
    export TOPAZHOME=`pwd`
fi

echo "TOPAZHOME set to $TOPAZHOME"
read -p "ok? ctrl-c to cancel"

export CLASSPATH=$CLASSPATH:$TOPAZHOME/chrome/content/signed2.jar:.
cd $TOPAZHOME/java_src/jTopaz/
#javac *java
for x in $@
do
    javac $x.java
done

mkdir $TOPAZHOME/java_src/jTopaz/temp
cp $TOPAZHOME/chrome/content/signed2.jar $TOPAZHOME/java_src/jTopaz/temp/
cd $TOPAZHOME/java_src/jTopaz/temp/
jar xf signed2.jar

cd jTopaz
mv $TOPAZHOME/java_src/jTopaz/*.class .
#for y in $@
#do
#    mv $TOPAZHOME/java_src/jTopaz/$y.class .
#done

cd ..
#mv signed2.jar ../signed2.jar.OLD
jar cf $TOPAZHOME/chrome/content/signed2new.jar ./COM/ ./cryptix/ ./javax/ ./jce-jdk13-131.jar ./jTopaz/ ./netscape/ ./org/ ./xjava/
cd $TOPAZHOME/java_src/jTopaz/
rm -r temp

# sign the jar... you can change cn=jaffee to cn=yourname
# instructions for jar signing http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html#appli
jarsigner -keystore topazstore -storepass storepass -keypass keypass -signedjar $TOPAZHOME/chrome/content/signed2.jar $TOPAZHOME/chrome/content/signed2new.jar topazFiles
